<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="__ROOT__/Public/Admin/shortcut icon" href="favicon.ico">
	<link href="__ROOT__/Public/Admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
	<link href="__ROOT__/Public/Admin/css/animate.css" rel="stylesheet">
	<link href="__ROOT__/Public/Admin/css/style.css?v=4.1.0" rel="stylesheet">
	
	<link href="__ROOT__/Public/Admin/js/plugins/bootstrap-editable/css/bootstrap-editable.css" rel="stylesheet" />
	<link href="__ROOT__/Public/Admin/js/plugins/bootstrap221/css/editable.css" rel="stylesheet" />
	<link href="__ROOT__/Public/Admin/js/plugins/sweetalert/sweetalert.css" rel="stylesheet">
	<style>
.table > thead > tr > th, .table > tbody > tr > th, .table > tfoot > tr > th, .table > thead > tr > td, .table > tbody > tr > td, .table > tfoot > tr > td {
	height:35px;
}
		.loading{
			 width: 35px;
			 height: 35px;
			 margin: 0 auto;
			 margin-top:100px;
			 position: fixed;
			 top: 0px;
			 left: 0px;
			 right: 0px;
			 bottom: 0px;
			 margin: auto;
		}
	</style>
	
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox float-e-margins">
            <div class="ibox-content">
                <table class="table table-bordered table-striped text-center" data-mobile-responsive="true">
                    <thead>
                    </thead>
                    <tbody>
                    	
                        <tr style="background-color:#efd38a !important; text-align:left;" >
                            <td colspan="10">项目名称：<span id="projectName"></span></td>
                        </tr>
                        
						<tr style="background-color:#efd38a !important; text-align:left;" >
                            <td colspan="10">项目周期：<span id="projectCycle"></span></td>
                        </tr>
                        
                        <tr style="background-color:#efd38a !important; text-align:left;" >
                            <td colspan="10">项目负责人：<span id="ChargeUserName"></span></td>
                        </tr>
                        
                        <tr style="background-color:#efd38a !important; text-align:left;" >
                            <td colspan="10">项目组成员：<span id="projectMember"></span></td>
                        </tr>
                        
                         <tr style="background-color:#efd38a !important; text-align:left;" >
                            <td colspan="10">项目概述：<span id="Intro"></span></td>
                        </tr>
                        
                        <tr style="background-color:#efd38a !important; text-align:left;" >
                            <td colspan="10">重要节点：<span id="ImportantPoint"></span></td>
                        </tr>
                        <tr style="background-color:#fb7022 !important; color: #FFFFFF;" id="Division">
                            <td>项目组分工</td>
                            <td>人员</td>
                            <td>角色</td>
                            <td colspan="4">工作任务分配</td>
                            <td>评价</td>
                        </tr>
                        
                     	<!-- tr id="toptr"></tr -->
                     	
                        <tr style="background-color:#ececec;" id="">
							<td colspan="7" >  
								<a onclick="additem(this,'l')">添加一条记录</a>
							</td>
						</tr>
						
                        <tr style="background-color:#FFFFFF !important;" >
                            <td style="background-color:#fb7022 !important; color: #FFFFFF;">项目奖励</td>
                            <td>发放奖励名单及百分比</td>
                            <td colspan="6" id="RewardContent" class="RewardContent" style="color:#686b6d"></td>
                        </tr>
                        
                        <tr style="background-color:#305cf1 !important; color: #FFFFFF;" >
                            <td>项目阶段</td>
                            <td>工作任务</td>
                            <td>时间</td>
                            <td>任务说明</td>
                            <td>项目方参与人员</td>
                            <td>业主方参与人员</td>
                            <td>成果文档及交付物</td>
                            <td>备注</td>
                        </tr>
						
						<tr id="toptr"></tr>
						<tr style="background-color:#ececec;" id="">
							<td colspan="8" >  
								<a onclick="additem(this,'c')">添加一条记录</a>
							</td>
						</tr>
						
                	</tbody>
          		</table>
            </div>
        </div>
    </div>
    <img src="__ROOT__/Public/Admin/img/loading.gif" class="loading" style="display:none;">	
</body>
<script src="__ROOT__/Public/Admin/js/jquery.min.js"></script>
<script src="__ROOT__/Public/Admin/js/plugins/laydate/laydate.js"></script>
<script src="__ROOT__/Public/Admin/js/plugins/bootstrap221/js/bootstrap.min.js"></script>
<script src="__ROOT__/Public/Admin/js/plugins/bootstrap-editable/js/bootstrap-editable.js"></script>
<script src="__ROOT__/Public/Admin/js/plugins/sweetalert/sweetalert.min.js"></script>
	
<link href="__ROOT__/Public/Admin/css/selector/selectorstyle.css" rel="stylesheet"/>
<script src="__ROOT__/Public/Admin/js/plugins/selector/selector.js"></script>
<script src="__ROOT__/Public/Admin/js/plugins/selector/jquery.ztree.all.js"></script>
<script>
	
	var projectID = 0;
	var SummaryID = 0; 
	<?php if(!empty($id)){echo "projectID = ".$id.";";}?>
	var i = 1, j = 1;
	tableGetData();
	function tableGetData(){
		$(".loading").show();
		var LaborHtml = "";
		var CommHtml = "";
	 	$.post("<?=U('Admin/ProjectSummary/save',array('type'=>'table','id'=>$id))?>",{},function(result){
	 		data = result;
	 		$("#projectName").html(data.projectName);
			$("#projectCycle").html(data.projectCycle+"天");
			$("#ChargeUserName").html(data.ChargeUserName);
			$("#projectMember").html(data.projectMember);
			$("#ImportantPoint").html(data.ImportantPoint);
			$("#Intro").html(data.Intro);
			$("#RewardContent").html(data.RewardContent);
			SummaryID = data.SummaryID;
			//项目组分工
			if(data.data[0] != undefined){
				if(data.data[0].Labor != undefined){
					$($('#Division').children("td").get(0)).attr('rowspan',data.data[0].Labor.length+2);
					var itme = data.data[0].Labor;
					for(var key in itme){
						for(var KEY in itme[key]){
							i++;
							LaborHtml = "<tr id="+itme[key][KEY][5].LID+" style='background-color:#FFFFFF !important;'><td class='UserName"+i+"' onclick=\"tablefun('UserID"+i+"','UserName"+i+"')\" data-toggle=\"modal\" data-target=\"#myModal\">"+ itme[key][KEY][0].UserName + "</td><td class='UserID"+i+"' style='display:none;'>"+ itme[key][KEY][4].UserID + "</td><td><div class='Role"+i+" myeditable'>"+itme[key][KEY][1].Role+"</div></td><td colspan='4'><div class='WorkContent"+i+" myeditable'>"+itme[key][KEY][2].WorkContent+"</div></td><td><div class='Eva"+i+" myeditable'>"+itme[key][KEY][3].Eva+"</div></td></tr>";
							$('#Division').after(LaborHtml);
							TieEvent();
						}
					}
				}
			}
			
			//项目沟通
			if(data.data[1] != undefined){
				if(data.data[1].Comm != undefined){
					var itme = data.data[1].Comm;
					for(var key in itme){
						for(var KEY in itme[key]){
							j++;
							CommHtml = "<tr id="+itme[key][KEY][8].LID+" style=\"background-color:#FFFFFF !important;\" ><td><div class='ProjectStage-"+j+" myeditable'>"+itme[key][KEY][0].ProjectStage+"</div></td><td><div class='WorkDuty-"+j+" myeditable'>"+itme[key][KEY][1].WorkDuty+"</div></td><td class='allDate-"+j+"'>"+itme[key][KEY][2].Date+"</td><td><div class='Description-"+j+" myeditable'>"+itme[key][KEY][3].Description+"</div></td><td><div class='ProjectMember-"+j+" myeditable'>"+itme[key][KEY][4].ProjectMember+"</div></td><td><div class='CustomMember-"+j+" myeditable'>"+itme[key][KEY][5].CustomMember+"</div></td><td><div class='OutputContent-"+j+" myeditable'>"+itme[key][KEY][6].OutputContent+"</td></div><td><div class='Memo-"+j+" myeditable'>"+itme[key][KEY][7].Memo+"</div></td></tr>";
						$("#toptr").before(CommHtml);
						TieEvent();
						}
					}
				}
			}
		
				$('.RewardContent').editable({ 
		            type: "textarea",             
		            title: "发放奖励名单及百分比",           
		            disabled: false,           
		            emptytext: "",
		            mode: "popup",          
		            validate: function (value) { //字段验证
		                if (!$.trim(value)) {
		                    return '不能为空';
		                }else{
		                	if(SummaryID == null || SummaryID == undefined){
		                		var data = {
				 					"ProjectID": projectID,
				 					"RewardContent": value
				 				}
		 						var url = "{:U('Admin/ProjectSummary/save')}&type=add";
		 						$.post(url,data,function(result){
								    if (result.status) {
								    	 swal({
								            title: "提示",
								            text: "操作成功！",
								            type: "success",
								            showCancelButton: false,
								            confirmButtonColor: "#DD6B55",
								            confirmButtonText: "确认",
								            cancelButtonText: "",
								            closeOnConfirm: false,
								            closeOnCancel: false
								       },function (isConfirm) {
								            document.location.reload();
								       });			
								    }else{
								    	swal("提示", result.info, "error");
								    }
								});
		                	}else{
		                		var updatedata = {
				 					"RewardContent": value,
				 					"ID": SummaryID
				 				}
		 						var url = "{:U('Admin/ProjectSummary/save')}&type=update";
		 						tableUpdate(updatedata,url);
		                	}
		                }
		            }
		     	});
			$(".loading").hide();
	 	});
	}
	     	
		function additem(dom,type){
			if(SummaryID == null || SummaryID == undefined) return alert("请先添加项目总结沟通");
			if(type == 'l'){
				i++;
				$($('#Division').children("td").get(0)).attr('rowspan',data.data[0].Labor.length+3);
				var newhtml = "<tr style='background-color:#FFFFFF !important;'><td class='UserName"+i+"' onclick=\"tablefun('UserID"+i+"','UserName"+i+"')\" data-toggle=\"modal\" data-target=\"#myModal\"></td><td class='UserID"+i+"' style='display:none;'><td><div class='Role"+i+" myeditable'></div></td><td colspan='4'><div class='WorkContent"+i+" myeditable'></div></td><td><div class='Eva"+i+" myeditable'></div></td></tr>";
				$(dom).attr('onclick', "tableAddData(this,'l')");
			}else if(type == 'c'){
				i++;
				var allDate = getNowFormatDate("date")+" ~ "+getNowFormatDate("date");
				var newhtml = "<tr style='background-color:#FFFFFF !important;'><td><div class='ProjectStage-"+j+" myeditable'></div></td><td><div class='WorkDuty-"+j+" myeditable'></div></td><td class='allDate-"+j+"'>"+allDate+"</td><td><div class='Description-"+j+" myeditable'></div></td><td><div class='ProjectMember-"+j+" myeditable'></div></td><td><div class='CustomMember-"+j+" myeditable'></div></td><td><div class='OutputContent-"+j+" myeditable'></div></td><td><div class='Memo-"+j+" myeditable'></div></td></tr>";
				$(dom).attr('onclick', "tableAddData(this,'c')");
			}
		  	$(dom).parent().parent().before(newhtml);
	     	$(dom).text("点击保存");
			TieEvent();
		}
	
	function tablefun(id,name){
 		openselector(id,name, function(name,id){
 			var timeid = $("."+name).parent().attr("id");
 			var uid = $("."+id).text();
 			if(timeid != undefined){
				var updatedata = {
					"ID" : timeid,
					"UserID" : uid
		 		}
				var url = "{:U('Admin/ProjectSummaryL/save')}&type=update";
 				tableUpdate(updatedata,url);
 			}
 		});
 	}
	
	function tableAddData(dom,type){
		var tr = $(dom).parent().parent().prev().children();
		var url = "";
		var data = {};
	 		if(type == 'l'){ 
	 			url = "{:U('Admin/ProjectSummaryL/save')}&type=add"; 
	 			data = {
		 			"PSID" : SummaryID,
		 			"UserID" : $(tr[1]).text(),
		 			"Role" : $(tr[2]).text(),
		 			"WorkContent" : $(tr[3]).text(),
		 			"Eva" : $(tr[4]).text()
	 			};
	 		}else if(type == 'c'){
	 			url = "{:U('Admin/ProjectSummaryC/save')}&type=add";
	 			var allDate = $(tr[2]).text();
	 			allDate = allDate.split(" ~ ");
	 			data = {
		 			"PSID" : SummaryID,
		 			"ProjectStage" :  $(tr[0]).text(),
		 			"WorkDuty" : $(tr[1]).text(),
		 			"StartDate" : allDate[0], 
		 			"EndDate" : allDate[1],
		 			"Description" : $(tr[3]).text(),
		 			"ProjectMember" : $(tr[4]).text(),
		 			"CustomMember" : $(tr[5]).text(),
		 			"OutputContent" : $(tr[6]).text(),
		 			"Memo" : $(tr[7]).text()
	 			};
	 		}
	 		$.post(url,data,function(result){
			    if (result.status) {
			    	 swal({
			            title: "继续操作？",
			            text: "操作成功！",
			            type: "success",
			            showCancelButton: false,
			            confirmButtonColor: "#DD6B55",
			            confirmButtonText: "确认",
			            cancelButtonText: "",
			            closeOnConfirm: false,
			            closeOnCancel: false
			       },function (isConfirm) {
			            document.location.reload();
			       });			
			    }else{
			    	swal("提示", result.info, "error");
			    }
			});
	}
	
		function TieEvent(){
			
			$(".Role"+i).editable({
	            type: "text", 
	            title: "角色",
	            disabled: false, 
	            emptytext: "",
	            //mode: "inline",
				url : function(params) {  
	               //console.info(params);
	            },
	            validate: function (value) { //字段验证
	                if (!$.trim(value)) {
	                    return '不能为空';
	                }else{
	                	var tr = $(this).parent().parent();
	                	if($(tr).attr("id") == undefined) return;
	                	var timeid = $(tr).attr("id");
	 					var updatedata = {
			 				"Role": value,
			 				"ID": timeid
			 			}
	 					var url = "{:U('Admin/ProjectSummaryL/save')}&type=update";
	 					tableUpdate(updatedata,url);
	                }
	            }
	        });
	        
	        $(".WorkContent"+i).editable({
	            type: "text", 
	            title: "工作任务分配",
	            disabled: false, 
	            emptytext: "",
	            //mode: "inline",
				url : function(params) {  
	               //console.info(params);
	            },
	            validate: function (value) { //字段验证
	                if (!$.trim(value)) {
	                    return '不能为空';
	                }else{
	                	var tr = $(this).parent().parent();
	                	if($(tr).attr("id") == undefined) return;
	                	var timeid = $(tr).attr("id");
	 					var updatedata = {
			 				"WorkContent": value,
			 				"ID": timeid
			 			}
	 					var url = "{:U('Admin/ProjectSummaryL/save')}&type=update";
	 					tableUpdate(updatedata,url);
	                }
	            }
	        });
	        
	        $(".Eva"+i).editable({
	            type: "text", 
	            title: "评价",
	            disabled: false, 
	            emptytext: "",
	            //mode: "inline",
				url : function(params) {  
	               //console.info(params);
	            },
	            validate: function (value) { //字段验证
	                if (!$.trim(value)) {
	                    return '不能为空';
	                }else{
	                	var tr = $(this).parent().parent();
	                	if($(tr).attr("id") == undefined) return;
	                	var timeid = $(tr).attr("id");
	 					var updatedata = {
			 				"Eva": value,
			 				"ID": timeid
			 			}
	 					var url = "{:U('Admin/ProjectSummaryL/save')}&type=update";
	 					tableUpdate(updatedata,url);
	                }
	            }
	        });
	        
	        $(".ProjectStage-"+j).editable({
	            type: "text", 
	            title: "项目阶段",
	            disabled: false, 
	            emptytext: "",
	            left : "10px",
	            //mode: "inline",
				url : function(params) {  
	               //console.info(params);
	            },
	            validate: function (value) { //字段验证
	                if (!$.trim(value)) {
	                    return '不能为空';
	                }else{
	                	var tr = $(this).parent().parent();
	                	if($(tr).attr("id") == undefined) return;
	                	var timeid = $(tr).attr("id");
	 					var updatedata = {
			 				"ProjectStage": value,
			 				"ID": timeid
			 			}
	 					var url = "{:U('Admin/ProjectSummaryC/save')}&type=update";
	 					tableUpdate(updatedata,url);
	                }
	            }
	        });
	        
	        $(".WorkDuty-"+j).editable({
	            type: "text", 
	            title: "工作任务",
	            disabled: false, 
	            emptytext: "",
	            //mode: "inline",
				url : function(params) {  
	               //console.info(params);
	            },
	            validate: function (value) { //字段验证
	                if (!$.trim(value)) {
	                    return '不能为空';
	                }else{
	                	var tr = $(this).parent().parent();
	                	if($(tr).attr("id") == undefined) return;
	                	var timeid = $(tr).attr("id");
	 					var updatedata = {
			 				"WorkDuty": value,
			 				"ID": timeid
			 			}
	 					var url = "{:U('Admin/ProjectSummaryC/save')}&type=update";
	 					tableUpdate(updatedata,url);
	                }
	            }
	        });
	        
	        $(".Description-"+j).editable({
	            type: "text", 
	            title: "任务说明",
	            disabled: false, 
	            emptytext: "",
	            //mode: "inline",
				url : function(params) {  
	               //console.info(params);
	            },
	            validate: function (value) { //字段验证
	                if (!$.trim(value)) {
	                    return '不能为空';
	                }else{
	                	var tr = $(this).parent().parent();
	                	if($(tr).attr("id") == undefined) return;
	                	var timeid = $(tr).attr("id");
	 					var updatedata = {
			 				"Description": value,
			 				"ID": timeid
			 			}
	 					var url = "{:U('Admin/ProjectSummaryC/save')}&type=update";
	 					tableUpdate(updatedata,url);
	                }
	            }
	        });
	        
	        $(".ProjectMember-"+j).editable({
	            type: "text", 
	            title: "项目方参与人员",
	            disabled: false, 
	            emptytext: "",
	            //mode: "inline",
				url : function(params) {  
	               //console.info(params);
	            },
	            validate: function (value) { //字段验证
	                if (!$.trim(value)) {
	                    return '不能为空';
	                }else{
	                	var tr = $(this).parent().parent();
	                	if($(tr).attr("id") == undefined) return;
	                	var timeid = $(tr).attr("id");
	 					var updatedata = {
			 				"ProjectMember": value,
			 				"ID": timeid
			 			}
	 					var url = "{:U('Admin/ProjectSummaryC/save')}&type=update";
	 					tableUpdate(updatedata,url);
	                }
	            }
	        });
	        
	        $(".CustomMember-"+j).editable({
	            type: "text", 
	            title: "业主方参与人员",
	            disabled: false, 
	            emptytext: "",
	            //mode: "inline",
				url : function(params) {  
	               //console.info(params);
	            },
	            validate: function (value) { //字段验证
	                if (!$.trim(value)) {
	                    return '不能为空';
	                }else{
	                	var tr = $(this).parent().parent();
	                	if($(tr).attr("id") == undefined) return;
	                	var timeid = $(tr).attr("id");
	 					var updatedata = {
			 				"CustomMember": value,
			 				"ID": timeid
			 			}
	 					var url = "{:U('Admin/ProjectSummaryC/save')}&type=update";
	 					tableUpdate(updatedata,url);
	                }
	            }
	        });
	        
	        $('.OutputContent-'+j).editable({ 
	            type: "textarea",             
	            title: "成果文档及交付物",           
	            disabled: false,           
	            emptytext: "",
	            mode: "popup",          
	            validate: function (value) { //字段验证
	                if (!$.trim(value)) {
	                    return '不能为空';
	                }else{
	                	var tr = $(this).parent().parent();
	                	if($(tr).attr("id") == undefined) return;
	                	var timeid = $(tr).attr("id");
	 					var updatedata = {
			 				"OutputContent": value,
			 				"ID": timeid
			 			}
	 					var url = "{:U('Admin/ProjectSummaryC/save')}&type=update";
	 					tableUpdate(updatedata,url);
	                }
	            }
	     	});
	     	
	     	$('.Memo-'+j).editable({ 
	            type: "textarea",             
	            title: "备注",           
	            disabled: false,           
	            emptytext: "",
	            mode: "popup",          
	            validate: function (value) { //字段验证
	                if (!$.trim(value)) {
	                    return '不能为空';
	                }else{
	                	var tr = $(this).parent().parent();
	                	if($(tr).attr("id") == undefined) return;
	                	var timeid = $(tr).attr("id");
	 					var updatedata = {
			 				"Memo": value,
			 				"ID": timeid
			 			}
	 					var url = "{:U('Admin/ProjectSummaryC/save')}&type=update";
	 					tableUpdate(updatedata,url);
	                }
	            }
	     	});
	     	
	     	laydate.render({
	            elem: '.allDate-'+j
	            ,type: 'date'
				,theme: 'molv'
	            ,range: '~'
	            ,change: function(value, date, endDate){
	            },done:function(value,date){
					var tr = $(this.elem).parent();
		            if($(tr).attr("id") == undefined) return;
		            var timeid = $(tr).attr("id");
	 				allDate = value.split(" ~ ");
		 			var updatedata = {
			 			"StartDate": allDate[0],
			 			"EndDate": allDate[1],
			 			"ID": timeid
			 		}
	 				var url = "{:U('Admin/ProjectSummaryC/save')}&type=update";
	 				tableUpdate(updatedata,url);
				}
	        });
		}
		
		function tableUpdate(updatedata,url){
			$(".loading").show();
	 		$.post(url,updatedata,function(result){
	 			$(".loading").hide();
	 			if (result.status) {
			       swal("提示", result.info, "success");
			    }else{
			    	swal({
			            title: "",
			            text: "修改失败 "+result.info,
			            type: "error",
			            showCancelButton: false,
			            confirmButtonColor: "#DD6B55",
			            confirmButtonText: "确认",
			            cancelButtonText: "",
			            closeOnConfirm: false,
			            closeOnCancel: false
			        },function (isConfirm) {
			            document.location.reload();
			        });		
			    }
	 		});
		}
		
		function getNowFormatDate(type) {
		    var date = new Date();
		    var seperator1 = "-";
		    var seperator2 = ":";
		    var month = date.getMonth() + 1;
		    var strDate = date.getDate();
		    if (month >= 1 && month <= 9) {
		        month = "0" + month;
		    }
		    if (strDate >= 0 && strDate <= 9) {
		        strDate = "0" + strDate;
		    }
		    if(type == "date"){
		    	var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
		    }else if(type == "time"){
		    	var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
		            + " " + date.getHours() + seperator2 + date.getMinutes()
		            + seperator2 + date.getSeconds();
		    }		    
		    return currentdate;
		}
</script>
</html>